﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="XmlDocElement.cs" company="NAntReflectionLib team">
//
// nant-cross-compile, an extension for NAnt for cross-compiling C/C++ applications.
// Copyright (C) 2012 nant-cross-compile team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/. 
// </copyright>
// <history>
//   <historyitem date="2013-02-24" change="Created file"/>
// </history>
// --------------------------------------------------------------------------------------------------------------------
namespace NAntReflectorLib
{
  using System.Collections.Generic;

  /// <summary>
  /// A XML element in a XML documentation document.
  /// </summary>
  public class XmlDocElement
  {
    /// <summary>
    /// The XML element type mapping.
    /// </summary>
    private static Dictionary<string, XmlDocElementType> xmlElementTypeMapping = new Dictionary<string, XmlDocElementType>
    {
      { "c", XmlDocElementType.CodeElement },
      { "code", XmlDocElementType.Code },
      { "cref", XmlDocElementType.Reference },
      { "description", XmlDocElementType.ListItemDescription },
      { "item", XmlDocElementType.ListItem },
      { "langword", XmlDocElementType.LanguageWord },
      { "list", XmlDocElementType.List },
      { "para", XmlDocElementType.Paragraph },
      { "remarks", XmlDocElementType.Remarks },
      { "see", XmlDocElementType.See },
      { "summary", XmlDocElementType.Summary },
      { "#text", XmlDocElementType.Text },
    };

    /// <summary>
    /// Initializes a new instance of the <see cref="XmlDocElement"/> class.
    /// </summary>
    /// <param name="name">The name.</param>
    /// <param name="value">The value.</param>
    public XmlDocElement(string name, string value)
    {
      this.Name = name;
      this.Value = value;
      this.Type = GetXmlElementType(name);
    }

    /// <summary>
    /// Gets the name.
    /// </summary>
    /// <value>
    /// The name.
    /// </value>
    public string Name { get; private set; }

    /// <summary>
    /// Gets the type.
    /// </summary>
    /// <value>
    /// The type.
    /// </value>
    public XmlDocElementType Type { get; private set; }

    /// <summary>
    /// Gets the value.
    /// </summary>
    /// <value>
    /// The value.
    /// </value>
    public string Value { get; private set; }

    /// <summary>
    /// Returns a <see cref="System.String" /> that represents this instance.
    /// </summary>
    /// <returns>
    /// A <see cref="System.String" /> that represents this instance.
    /// </returns>
    public override string ToString()
    {
      return this.Value;
    }

    /// <summary>
    /// Gets the type of the XML element.
    /// </summary>
    /// <param name="name">The name.</param>
    /// <returns>The type of the element.</returns>
    private static XmlDocElementType GetXmlElementType(string name)
    {
      if (xmlElementTypeMapping.ContainsKey(name))
      {
        return xmlElementTypeMapping[name];
      }
      else
      {
        return XmlDocElementType.Unknown;
      }
    }
  }
}
